﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ControlCenter.ApplicationService;
using ControlCenter.Model;
using ControlCenter.Model.BizEntities;
using ControlCenter.Model.WebApiDto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MingYuanyun.WebApi.Abstractions;

namespace ControlCenterService.WebApi.Controllers
{
    /// <summary>
    /// 文档服务Api
    /// </summary>
    [Route("[controller]")]
    public class DocController : BasicController
    {
        private readonly IFileService _fileService;

        /// <summary>
        /// 类初始化
        /// </summary>
        public DocController(IFileService fileService)
        {
            _fileService = fileService;
        }

        /// <summary>
        /// 上传文档（使用者：控制中心）
        /// </summary>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        [RequestFormLimits(MultipartBodyLengthLimit = 309715200)]
        [RequestSizeLimit(309715200)]
        [HttpPost]
        [Route("upload")]
        public async Task<HttpRequestResult<UploadNupkgFileReturnDto>> Upload(IFormFile file, [FromQuery]string type)
        {
            return OkHttpRequestResult(await _fileService.UploadPackage(file, type));
        }
    }
}
